package com.yuch.commons;

import lombok.Data;

/**
 * 统一封装处理
 */
@Data
public class R<T> {
    private Integer code;

    private T data;

    private String msg;

    public static <T> R<T> success(T data) {
        R<T> r = new R<T>();
        r.code = 1;
        r.msg = null;
        r.data = data;
        return r;

    }

    public static <T> R<T> error(String msg) {
        R<T> r = new R<T>();
        r.code = 0;
        r.data = null;
        r.msg = msg;
        return r;
    }

    public static R code(Boolean code) {
        R r = new R<>();
        r.code = code ? 1 : 0;
        r.data = null;
        r.msg = null;
        return r;
    }

}
